package com.star.star.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.star.star.Activity.AidDetailsActivity;
import com.star.star.Activity.mineActivity;
import com.star.star.R;
import com.star.star.bean.abean;
import com.star.star.bean.aidBean;
import com.star.star.utils.CircleImageView;

import java.util.List;

public class aidAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<abean> daBeans;

    public aidAdapter(Context context, List<abean> daBeans) {
        this.context = context;
        this.daBeans = daBeans;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_item_aid, parent, false);
        return new MYholder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        MYholder mYholder = (MYholder) holder;
        mYholder.setdata(position);
        mYholder.tv_clock.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, mineActivity.class);
                intent.putExtra("iv",daBeans.get(position).getUrl());
                intent.putExtra("name",daBeans.get(position).getName());
                intent.putExtra("num",daBeans.get(position).getNum());
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return daBeans.size();
    }

    private class MYholder extends RecyclerView.ViewHolder {

        private final CircleImageView imageView;
        private final TextView tv_name,tv_number,tv_clock;
        private  final RelativeLayout rl_gone;

        public MYholder(View view) {
            super(view);
            imageView = view.findViewById(R.id.iv_image);
            tv_name = view.findViewById(R.id.tv_name);
            tv_number = view.findViewById(R.id.tv_number);
            tv_clock = view.findViewById(R.id.tv_clock);
            rl_gone = view.findViewById(R.id.rl_gone);
        }

        public void setdata(int position) {
            if (position!=0){
                rl_gone.setVisibility(View.GONE);
            }else {
                rl_gone.setVisibility(View.VISIBLE);
            }
            Glide.with(context).load(daBeans.get(position).getUrl()).placeholder(R.mipmap.no_hand).error(R.mipmap.no_hand).into(imageView);
            tv_name.setText(daBeans.get(position).getName());
            tv_number.setText(daBeans.get(position).getNum());
         }
    }
}
